import http from './http'
import { store } from '../store'
import { Dialog } from 'vant'
import router from '../router'

export default {
  getBanners(params) {

   return http.get('/banner',{params})
     .then((res) => {
       store.commit('getBanners',res.data.banners);
       })
     .catch((err) => {
       Dialog.confirm({
         title:'警告',
         message:'404',
       })
         .then(function () {
           router.push({path:'/login',query:{} })
         })
         .catch(function () {
             router.push('/phone_login')
           }
         )
     })
  },
  gettodayArray(params){
    return http.get('http://localhost:3000/personalized',{params})
      .then((res) => {
        store.commit('gettodayArray',res.data.result);
      })
  },
  gethavelook(params){
    return http.get('http://localhost:3000/top/artists',{params})
      .then((res) => {
        store.commit('gethavelook',res.data.artists);
      })
  },
  getanchor(params){
    return http.get('/personalized/djprogram',{params})
      .then((res) => {
        store.commit('getanchor',res.data.result);
      })
  },
  getthelatest(params){
    return http.get('/top/album',{params})
      .then((res) => {
        store.commit('getthelatest',res.data.albums);
      })
  },
  getpreferably(params){
    return http.get('/dj/today/perfered',{params})
      .then((res) => {
        store.commit('getpreferably',res.data.data);
      })
  },
  getboutique(params){
    return http.get('/dj/paygift',{params})
      .then((res) => {
        store.commit('getboutique',res.data.data.list);
      })
  },
  getcreation(params){
    return http.get('/dj/category/recommend',{params})
      .then((res) => {
        store.commit('getcreation',res.data.data);
      })
  },
  getheader(params){
    return http.get('/search/default',{params})
      .then((res) => {
        store.commit('getheader',res.data.data.showKeyword);
      })
  },
  getfriend(params){
    return http.get('/user/follows',{params})
      .then((res) => {
        store.commit('getfriend',res.data.follow);
      })
  }

};
